ErrorHandler.js ➔ render   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 14
ccs 3
cts 4
cp 0.75
rs 9.8
c 0
b 0
f 0
cc 2
crap 2.0625
1
import React from 'react';
2
import * as PropTypes from 'prop-types';
3
import './ErrorHandler.scss';
4
import { Button } from 'reactstrap';
5
6
// FIXME Replace with typescript: (window, console)
7 2
const ErrorHandler = ({ location }, { error }) => class ErrorHandler extends React.Component {
8 2
  static propTypes = {
9
    children: PropTypes.node.isRequired,
10
  };
11
12
  constructor(props) {
13 2
    super(props);
14 2
    this.state = { hasError: false };
15
  }
16
17
  static getDerivedStateFromError() {
18
    return { hasError: true };
19
  }
20
21
  componentDidCatch(e) {
22 2
    if (process.env.NODE_ENV !== 'development') {
23
      error(e);
24
    }
25
  }
26
27
  render() {
28 3
    if (this.state.hasError) {
29 1
      return (
30
        <div className="error-handler">
31
          <h1>Oops! This is awkward :S</h1>
32
          <p>It seems that something went wrong. Try refreshing the page or just click this button.</p>
33
          <br />
34
          <Button outline color="primary" onClick={() => location.reload()}>Take me back</Button>
35
        </div>
36
      );
37
    }
38
39 2
    return this.props.children;
40
  }
41
};
42
43
export default ErrorHandler;
44